package demo20;

import java.util.Random;

class Producer extends Thread{
    @Override
    public void run() {
        setName("生产者");
        try {
            Random random = new Random();
            while (true) {
                Test.queue.put(random.nextLong());
            }
        } catch (InterruptedException exc){
            exc.printStackTrace();
        }
    }
}

class Customer extends Thread{
    @Override
    public void run() {
        setName("消费者");
        try {
            while (true){
                Long take = Test.queue.take();
            }
        } catch (InterruptedException exc){
            exc.printStackTrace();
        }
    }
}

public class Test {
    static MyBlockingQueue queue = new MyBlockingQueue(10);

    public static void main(String[] args) {
        for (int i = 0; i < 1; i++){
            new Producer().start();
        }

        for (int i = 0; i < 50; i++){
            new Customer().start();
        }
    }
}
